package jdbc;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class aa extends JFrame {

	private JPanel contentPane;
	private JTextField name;
	private JTextField kor;
	private JTextField eng;
	private JTextField mat;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					aa frame = new aa();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public aa() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel title = new JLabel("성적");
		title.setBounds(374, 125, 57, 15);
		panel.add(title);
		
		JLabel namelbl = new JLabel("이름");
		namelbl.setBounds(147, 208, 57, 15);
		panel.add(namelbl);
		
		JLabel korlbl = new JLabel("국어");
		korlbl.setBounds(162, 284, 57, 15);
		panel.add(korlbl);
		
		JLabel englbl = new JLabel("영어");
		englbl.setBounds(147, 334, 57, 15);
		panel.add(englbl);
		
		JLabel matlbl = new JLabel("수학");
		matlbl.setBounds(147, 394, 57, 15);
		panel.add(matlbl);
		
		name = new JTextField();
		name.setBounds(258, 205, 116, 21);
		panel.add(name);
		name.setColumns(10);
		
		kor = new JTextField();
		kor.setBounds(231, 281, 116, 21);
		panel.add(kor);
		kor.setColumns(10);
		
		eng = new JTextField();
		eng.setBounds(230, 331, 116, 21);
		panel.add(eng);
		eng.setColumns(10);
		
		mat = new JTextField();
		mat.setBounds(230, 391, 116, 21);
		panel.add(mat);
		mat.setColumns(10);
		
		JButton btnok = new JButton("입력완료");
		btnok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SungjukVO sj = new SungjukVO();
				
				String msg = name.getText() + "/" + kor.getText() + "/" + eng.getText() + "/" + mat.getText();
				sj.setName(name.getText());
				sj.setKor(kor.getText());
				sj.setEng(eng.getText());
				sj.setMat(mat.getText());
				new SungJukservice().createsungjuk(sj);
				msg += "\n" + sj.getTot() + "/" + sj.getAvg();
				JOptionPane.showMessageDialog(null, msg);
				
				
			}
		});
		btnok.setBounds(162, 457, 97, 23);
		panel.add(btnok);
		
		JButton btnreset = new JButton("입력취소");
		btnreset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				name.setText("");
				kor.setText("");
				eng.setText("");
				mat.setText("");
			}
		});
		btnreset.setBounds(298, 457, 97, 23);
		panel.add(btnreset);
	}

}
class SungjukVO{
	private String name;
	private String kor;
	private String eng;
	private String mat;
	private String tot;
	private String avg;
	private String grd;
	public String getTot() {
		return tot;
	}
	public void setTot(String tot) {
		this.tot = tot;
	}
	public String getAvg() {
		return avg;
	}
	public void setAvg(String avg) {
		this.avg = avg;
	}
	public String getGrd() {
		return grd;
	}
	public void setGrd(String grd) {
		this.grd = grd;
	}
	public SungjukVO() {}
	public SungjukVO(String name,String eng, String mat) { 
		this.name = name;
		this.eng = eng;
		this.mat = mat;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getKor() {
		return kor;
	}
	public void setKor(String kor) {
		this.kor = kor;
	}
	public String getEng() {
		return eng;
	}
	public void setEng(String eng) {
		this.eng = eng;
	}
	public String getMat() {
		return mat;
	}
	public void setMat(String mat) {
		this.mat = mat;
	}
	
	
}

class SungJukservice{
	public boolean createsungjuk(SungjukVO sj) {
		boolean result = false;
		computesungjuk(sj);
		return result;
	}
private void computesungjuk(SungjukVO sj){
		int tot = Integer.parseInt(sj.getKor()) + Integer.parseInt(sj.getEng()) + Integer.parseInt(sj.getMat());
		float avg = (float) tot/ 3;
		sj.setTot(tot+"");
		sj.setAvg(avg+"");
	}
}
